import { UserRepository } from '@/examples/user/user.repository';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';

@Injectable()
export class AdminGuard implements CanActivate {

  constructor(private userService: UserRepository){}

  async canActivate(
    context: ExecutionContext,
  ): Promise<any> {
    //1.获取请求对象
    const req = context.switchToHttp().getRequest();

    if(req.user) {
      const {username} = req.user
      const user = await this.userService.find(username)
    
    }
    // req->headers->jwt->payload
    //2. 获取用户信息 加入逻辑判断->角色判断->权限判断
    
    return true;
  }
}
